#include <iostream>
#include <stack>
#include <string>

bool isBalanced(const std::string& sequence) {
    std::stack<char> stack;
    for (char c : sequence) {
        if (c == '(' || c == '[' || c == '{' || c == '<') {
            stack.push(c);
        } else if (c == ')' || c == ']' || c == '}' || c == '>') {
            if (stack.empty()) {
                return false;
            }
            char top = stack.top();
            stack.pop();
            if ((c == ')' && top != '(') ||
                (c == ']' && top != '[') ||
                (c == '}' && top != '{') ||
                (c == '>' && top != '<')) {
                return false;
            }
        }
    }
    return stack.empty();
}

int main() {
    std::string sequence;
    std::cout << "Введите скобочную последовательность: ";
    std::cin >> sequence;
    bool balanced = isBalanced(sequence);
    std::cout << (balanced ? "True" : "False") << std::endl;
    return 0;
}